﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Peekaboo2008.dao;
using Peekaboo2008.model;

namespace Peekaboo2008.view
{
    public partial class FormDonViQuiDoi : Form
    {
        public FormDonViQuiDoi()
        {
            InitializeComponent();
            loadValue();
        }

        public void loadValue()
        {
            DataTable dt =  DonViQuiDoiDAO.GetAll();
            dvgDonViQuiDoi.DataSource = dt;

            //Danh Mục Đơn Vị Qui Đổi
        }

        private void FormDonViQuiDoi_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F5)
            {
                tsbThem.PerformClick();
            }
            else if (e.KeyCode == Keys.F4)
            {
                tsbThoat.PerformClick();
            }
        }

        private void FormDonViQuiDoi_Load(object sender, EventArgs e)
        {
            this.KeyPreview = true;
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FormDonViQuiDoi_KeyDown);
        }

        private void tsbThem_Click(object sender, EventArgs e)
        {
            FormDonViQuiDoi formDonViQuiDoi = this ;
            FormChiTietDonViQuiDoi formChiTietDonViQuiDoi = new FormChiTietDonViQuiDoi(ref formDonViQuiDoi);
            formChiTietDonViQuiDoi.ShowDialog();
        }

        private void dvgDonViQuiDoi_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            DonViQuiDoiModel model = new DonViQuiDoiModel();
            model.Id = dvgDonViQuiDoi.CurrentRow.Cells["id"].Value.ToString();
            model.DonViGoc = dvgDonViQuiDoi.CurrentRow.Cells["DonViGoc"].Value.ToString();
            model.ChildId = dvgDonViQuiDoi.CurrentRow.Cells["ChildID"].Value.ToString();
            model.SoLuong = dvgDonViQuiDoi.CurrentRow.Cells["SoLuong"].Value.ToString();
            model.GhiChu = dvgDonViQuiDoi.CurrentRow.Cells["GhiChu"].Value.ToString();
            FormDonViQuiDoi formDonViQuiDoi = this;
            FormChiTietDonViQuiDoi formChiTietDonViQuiDoi = new FormChiTietDonViQuiDoi(ref formDonViQuiDoi,model);
            formChiTietDonViQuiDoi.ShowDialog();

        }

        private void tsbThoat_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}
